cmake_minimum_required(VERSION 3.26)  # 3.19
project(yolov8_detect_trt_cpp)
set(CMAKE_BUILD_TYPE Release)  # 配置编译类型 Debug、Release  debug检测时间比release长

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include_directories("yolov8_detect_trt_cpp/")

# CUDA
set(CUDA_DIR C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.8)
find_package(CUDA REQUIRED)
include_directories(${CUDA_INCLUDE_DIRS})
message(STATUS "Find CUDA include at ${CUDA_INCLUDE_DIRS}")
message(STATUS "Find CUDA libraries: ${CUDA_LIBRARIES}")

# TensorRT
set(TENSORRT_ROOT D:/aiSoft/TensorRT-8.5.3.1)
find_path(TENSORRT_INCLUDE_DIR NvInfer.h
        HINTS ${TENSORRT_ROOT} PATH_SUFFIXES include/)
message(STATUS "Found TensorRT headers at ${TENSORRT_INCLUDE_DIR}")
find_library(TENSORRT_LIBRARY_INFER nvinfer
        HINTS ${TENSORRT_ROOT} ${TENSORRT_BUILD} ${CUDA_TOOLKIT_ROOT_DIR}
        PATH_SUFFIXES lib lib64 lib/x64)
find_library(TENSORRT_LIBRARY_ONNXPARSER nvonnxparser
        HINTS ${TENSORRT_ROOT} ${TENSORRT_BUILD} ${CUDA_TOOLKIT_ROOT_DIR}
        PATH_SUFFIXES lib lib64 lib/x64)
set(TENSORRT_LIBRARY ${TENSORRT_LIBRARY_INFER} ${TENSORRT_LIBRARY_ONNXPARSER})
include_directories(${TENSORRT_INCLUDE_DIR})
message(STATUS "Find TensorRT libs: ${TENSORRT_LIBRARY}")

# OpenCV
# opencv下载后的路径,opencv编译路径
set(OpenCV_DIR D:/aiSoft/opencv-4.8.0/opencv/build/x64/vc16/lib)
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
# 打印消息
message(STATUS "Find OpenCV include at ${OpenCV_INCLUDE_DIRS}")
message(STATUS "Find OpenCV libraries: ${OpenCV_LIBRARIES}")

add_executable(${PROJECT_NAME} trt_run.cpp detect_file.cpp)

# 链接的所有 .lib库文件
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBRARIES} ${CUDA_LIBRARIES} ${TENSORRT_LIBRARY})
